<%@ taglib prefix="spring-tags" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="spring-form" uri="http://www.springframework.org/tags/form"%>
<%@ page
    import="org.jiscinvolve.astrodabis.barberry.control.Paths"
    import="org.jiscinvolve.astrodabis.barberry.control.ObjectData"
    import="org.jiscinvolve.astrodabis.barberry.control.RequestData"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Tag"
    import="org.jiscinvolve.astrodabis.barberry.common.core.Account"
    import="org.jiscinvolve.astrodabis.barberry.common.data.TapService"
    import="org.jiscinvolve.astrodabis.barberry.common.data.TapTable"
    import="org.jiscinvolve.astrodabis.barberry.common.data.TapColumn"
    import="org.jiscinvolve.astrodabis.barberry.common.data.TapRow"
    import="org.jiscinvolve.astrodabis.barberry.common.data.TapJoin"
    import="org.jiscinvolve.astrodabis.barberry.common.data.RowTag"
    import="org.jiscinvolve.astrodabis.barberry.common.data.JoinTag"
    session="true"
%><%
ObjectData<TapRow> data = (ObjectData<TapRow>) request.getAttribute(
    RequestData.MODEL_ATTRIB
    ) ;
Account actor = data.actor();
TapRow row = data.object();
%>
<html>
    <head>
	    <title>AstroDAbis row <%= row.ident() %></title>
        <link href='<%= data.file("css/page.css") %>' rel='stylesheet' type='text/css'/>
    </head>
    <body>
        <%@ include file="/jsp/header.jsp" %>
        <div class='body'>
            <div class='left'>
                <%@ include file="/jsp/menu.jsp" %>
            </div>
            <div class='right'>
                <a href='<%= data.link(row) %>'>
                    <img src='<%= data.qrcode(data.link(row)) %>'/>
                </a>
            </div>
            <div class='content'>
        	    <h2>Row <%= row.ident() %></h2>
                <fieldset>
                    <legend>Row details</legend>
                    <div>
                        <ul>
                            <li>
                                Service : <a href='<%= data.link(row.parent().parent().parent()) %>'><%= row.parent().parent().parent().name() %></a>
                            </li>
                            <li>
                                Table : <a href='<%= data.link(row.parent().parent()) %>'><%= row.parent().parent().name() %></a>
                            </li>
                            <li>
                                Column : <a href='<%= data.link(row.parent()) %>'><%= row.parent().name() %></a>
                            </li>
                            <li>
                                Row  : <%= row.value() %>
                            </li>
                        </ul>
                    </div>
                </fieldset>

                <fieldset>
                    <legend>Row tags</legend>
                    <table>
                        <thead>
                            <tr>
                                <td>row-tag</td>
                                <td>owner</td>
                                <td>name</td>
                                <td>value</td>
                            </tr>
                        </thead>
                        <tbody>
                            <%
                            for (RowTag rowtag : row.tags().select())
                                {
                                %>
                                <tr>
                                    <td>
                                        <a href="<%= data.link(rowtag) %>">[<%= rowtag.ident() %>]</a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(rowtag.tag().owner()) %>"><%= rowtag.tag().owner().name() %></a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(rowtag.tag()) %>"><%= rowtag.tag().name() %></a>
                                    </td>
                                    <td>
                                        <%= (rowtag.value() != null) ? rowtag.value() : "&nbsp" %>
                                    </td>
                                </tr>
                                <%
                                }
                            %>
                        </tbody>
                    </table>
                </fieldset>

                <fieldset>
                    <legend>Joins</legend>
                    <table>
                        <thead>
                            <tr>
                                <td>join</td>
                                <td>table</td>
                                <td>column</td>
                                <td>row</td>
                            </tr>
                        </thead>
                        <tbody>
                            <%
                            for (TapJoin join : row.joins().select(TapJoin.SelectType.SAME))
                                {
                                %>
                                <tr>
                                    <td>
                                        <a href="<%= data.link(join) %>">[<%= join.ident() %>]</a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(join.two().parent().parent()) %>"><%= join.two().parent().parent().name() %></a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(join.two().parent()) %>"><%= join.two().parent().name() %></a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(join.two()) %>"><%= join.two().value() %></a>
                                    </td>
                                </tr>
                                <%
                                }
                            %>
                        </tbody>
                    </table>
                </fieldset>

                <fieldset>
                    <legend>Inverse joins</legend>
                    <table>
                        <thead>
                            <tr>
                                <td>join</td>
                                <td>table</td>
                                <td>column</td>
                                <td>row</td>
                            </tr>
                        </thead>
                        <tbody>
                            <%
                            for (TapJoin join : row.joins().select(TapJoin.SelectType.SWAP))
                                {
                                %>
                                <tr>
                                    <td>
                                        <a href="<%= data.link(join) %>">[<%= join.ident() %>]</a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(join.one().parent().parent()) %>"><%= join.one().parent().parent().name() %></a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(join.one().parent()) %>"><%= join.one().parent().name() %></a>
                                    </td>
                                    <td>
                                        <a href="<%= data.link(join.one()) %>"><%= join.one().value() %></a>
                                    </td>
                                </tr>
                                <%
                                }
                            %>
                        </tbody>
                    </table>
                </fieldset>

            </div>
        </div>
        <%@ include file="/jsp/footer.jsp" %>
    </body>
</html>

